<?php
  /***************************************************************
   * @file: Pagination.class.php
   * @author: Neo
   * @mail: xq262144@gmail.com
   * @date: 
   * @description:
   * this file is the error controlling model
   ***************************************************************/
      
  
	function generate_pagination( $baseURL, $pageInfo ){
        if ( !isset( $pageInfo['pageCount'] ) || $pageInfo['pageCount'] == 0 || $pageInfo['pageCount'] == 1 )
        {
            return null;
        }
        else
        {
            $ret = '<div class="pagination">';
            if ( !$pageInfo['isFirst'] ) 
            {
                $ret .= sprintf( '<a href="%s" style="padding: 0 2px;">%s</a>',
                    $baseURL . ( 1 ) . '/' . $pageInfo['pageSize'],
                        htmlspecialchars('<<首页') );
                $ret .= sprintf( '<a href="%s" style="padding: 0 2px;">%s</a>',
                    $baseURL . ( $pageInfo['page'] - 1 ) . '/' . 
                        $pageInfo['pageSize'], htmlspecialchars( '<上一页' ) );
            }

            for ( $v = 0; $v != $pageInfo['pageCount']; ++$v )
            {
                $ret .= sprintf( 
                    ( $pageInfo['page'] == ( $v + 1 ) ) ? 
                        '<span style="padding: 0 2px;">%d</span>' : '<a href="%2$s" style="padding: 0 2px;">%1$d</a>',
                    $v + 1, $baseURL . ( $v + 1 ) . '/' . $pageInfo['pageSize'] );
            }

            if ( !$pageInfo['isLast'] )
            {
                $ret .= sprintf( '<a href="%s" style="padding: 0 2px;">%s</a>',
                    $baseURL . ( $pageInfo['page'] + 1 ) . '/' . 
                        $pageInfo['pageSize'], htmlspecialchars( '下一页>' ) );
                $ret .= sprintf( '<a href="%s" style="padding: 0 2px;">%s</a>',
                    $baseURL . ( $pageInfo['pageCount'] ) . '/' . $pageInfo['pageSize'],
                        htmlspecialchars('末页>>') );
            }

            $ret .= '</div>';

            return $ret;
        }
  	}
  